package com.huangsm.book.designmodel.parallel.future;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @author huang
 * @PACKAGE_NAME com.huangsm.book.designmodel.parallel.future
 * @PROJECT_NAME concurrence
 * @date 2019/2/18
 */
public class JDKMain {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //构造FutureTask
        FutureTask<String> future = new FutureTask<>(new JDKRealData("a"));
        ExecutorService executor = Executors.newFixedThreadPool(1);
        //执行FutureTask，相当于自定义中的client.request("a")发送请求
        //在这里开启线程进行RealData的call执行
        executor.submit(future);
        System.out.println("请求完毕");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(future.get());
    }
}
